﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace _00_WPF基础.控件
{
	/// <summary>
	/// A19_DataGird1.xaml 的交互逻辑
	/// </summary>
	public partial class A19_DataGrid1 : Window
	{
		public A19_DataGrid1()
		{
			InitializeComponent();
		}

		private void Window_Loaded(object sender, RoutedEventArgs e)
		{
			//方法1 设置combox数据源
			//dataGrid_Department.DisplayMemberPath = "DepartmentName";
			//dataGrid_Department.SelectedValuePath = "DepartmentID";
			//dataGrid_Department.ItemsSource = GetDepartment();

			//方法2 通过dataGrid索引获取dataGrid_Department
			//DataGridComboBoxColumn department = dataGird.Columns[3] as DataGridComboBoxColumn;
			//department.ItemsSource = GetDepartment();

			//dataGird.ItemsSource = GetPerson();

			//用MVVM方式
			DataGridViewModel dataGridViewModel = new DataGridViewModel();
			dataGridViewModel.departmentInfo = GetDepartment();
			dataGridViewModel.personList = GetPerson();
			this.DataContext = dataGridViewModel;

		}

		public List<DepartmentInfo> GetDepartment()
		{
			List<DepartmentInfo> list = new List<DepartmentInfo>();
			list.Add(new DepartmentInfo("1", "技术部"));
			list.Add(new DepartmentInfo("2", "人事部"));
			list.Add(new DepartmentInfo("3", "业务部"));
			list.Add(new DepartmentInfo("4", "业务部1"));
			list.Add(new DepartmentInfo("5", "业务部2"));
			list.Add(new DepartmentInfo("6", "业务部3"));
			return list;
		}


		public List<Person> GetPerson()
		{
			List<Person> person = new List<Person>();
			person.Add(new Person(1, "张十三", true, "技术部", 20));
			person.Add(new Person(2, "张三", false, "人事部", 21));
			person.Add(new Person(3, "张十", true, "业务部", 23));

			//person.Add(new Person(1, "张十三", true, 1, 20));
			//person.Add(new Person(2, "张三", false, 1, 21));
			//person.Add(new Person(3, "张十", true, 3, 23));
			return person;
		}
	}

	public class Person
	{
		public Person(int UserId, string UserName, bool UserState, string DepartmentID, int UserAge)
		{
			userId = UserId;
			userName = UserName;
			userState = UserState;
			departmentID = DepartmentID;
			userAge = UserAge;
		}

		private int userId;
		private string userName;
		private bool userState;
		private string departmentID;
		private int userAge;

		public int UserId { get { return userId; } set { userId = value; } }
		public string UserName { get { return userName; } set { userName = value; } }
		public bool UserState { get { return userState; } set { userState = value; } }
		public string DepartmentID { get { return departmentID; } set { departmentID = value; } }
		public int UserAge { get { return userAge; } set { userAge = value; } }
	}

	public class DepartmentInfo
	{
		public DepartmentInfo(string DepartmentID, string DepartmentName)
		{
			departmentID = DepartmentID;
			departmentName = DepartmentName;
		}

		private string departmentID;
		private string departmentName;

		public string DepartmentID { get { return departmentID; } set { departmentID = value; } }
		public string DepartmentName { get { return departmentName; } set { departmentName = value; } }
	}

	public class DataGridViewModel
	{
		public List<Person> personList { get; set; }
		public List<DepartmentInfo> departmentInfo { get; set; }
	}
}
